Skip to content

fix: batch NFT ownership checks via Multicall3#8281

Merged
juanmigdr merged 12 commits intomainfrom
fix/do-not-make-On-calls-fo-refresh
Apr 10, 2026
Merged

fix: batch NFT ownership checks via Multicall3#8281
juanmigdr merged 12 commits intomainfrom
fix/do-not-make-On-calls-fo-refresh

Conversation

@juanmigdr
Copy link
Copy Markdown
Member

@juanmigdr juanmigdr commented Mar 24, 2026

Explanation

  • Replace individual AssetsContractController messenger calls (getERC721OwnerOf, getERC1155BalanceOf) with a new getNftOwnershipForMultipleNfts utility that batches ERC-721 ownerOf and ERC-1155 balanceOf calls through Multicall3's aggregate3, falling back to individual RPC calls on unsupported chains or when multicall fails.
  • Remove checkAndUpdateSingleNftOwnershipStatus in favor of checkAndUpdateAllNftsOwnershipStatus, which now batches all NFTs in a single pass.
  • Add an optional standard parameter to isNftOwner so callers that already know the token standard skip redundant subcalls.
  • checkAndUpdateAllNftsOwnershipStatus now removes NFTs confirmed as unowned from state rather than retaining them with isCurrentlyOwned: false. The "Previously Owned" NFT feature this flag powered is no longer supported.

Breaking Changes

  • checkAndUpdateSingleNftOwnershipStatus removed — use checkAndUpdateAllNftsOwnershipStatus instead.
  • AllowedActions narrowedAssetsContractController:getERC721OwnerOf and AssetsContractController:getERC1155BalanceOf are no longer required by NftController's messenger. Consumers constructing the messenger must remove these from their allowed actions list.

References

Ticket: https://consensyssoftware.atlassian.net/browse/ASSETS-2959
PR on Mobile: MetaMask/metamask-mobile#28655
PR on Extension:

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've communicated my changes to consumers by updating changelogs for packages I've changed
  • I've introduced breaking changes in this PR and have prepared draft pull requests for clients and consumer packages to resolve them

Note

Medium Risk
Medium risk due to breaking API surface (AllowedActions narrowed, checkAndUpdateSingleNftOwnershipStatus removed) and changed state semantics (unowned NFTs are deleted), plus new multicall batching logic that could affect ownership determination across networks.

Overview
NFT ownership checks are refactored to batch on-chain calls via Multicall3. NftController.isNftOwner and checkAndUpdateAllNftsOwnershipStatus now use the new getNftOwnershipForMultipleNfts helper to aggregate ERC-721 ownerOf / ERC-1155 balanceOf calls (with fallback to individual calls when multicall/chain support is unavailable), and callers can pass an optional standard to skip unnecessary subcalls.

Breaking behavior changes: AssetsContractController:getERC721OwnerOf and AssetsContractController:getERC1155BalanceOf are removed from NftController AllowedActions, checkAndUpdateSingleNftOwnershipStatus is removed, and ownership refresh now removes NFTs confirmed as unowned from state instead of setting isCurrentlyOwned: false. Tests and changelog are updated accordingly, and multicall gains comprehensive coverage for the new NFT ownership batching utility.

Reviewed by Cursor Bugbot for commit f782f90. Bugbot is set up for automated code reviews on this repo. Configure here.

@juanmigdr juanmigdr requested a review from a team as a code owner March 24, 2026 12:36
Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 09a4cdc. Configure here.

@juanmigdr juanmigdr enabled auto-merge April 10, 2026 11:25
@juanmigdr juanmigdr added this pull request to the merge queue Apr 10, 2026
Merged via the queue into main with commit d148dd7 Apr 10, 2026
341 checks passed
@juanmigdr juanmigdr deleted the fix/do-not-make-On-calls-fo-refresh branch April 10, 2026 12:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants